<template>
<!-- {show:y>=78}判断是否为真，为真就加上show这个类名 -->
  <div class="app-header-sticky" :class="{show:y>78}">
    <!-- 当y>=78显示，不然在y小于78的时候会出现两个组件 -->
    <div class="container"  v-show="y>78">
      <RouterLink class="logo" to="/" />
      <HeaderNav />
      <div class="right">
        <RouterLink to="/" >品牌</RouterLink>
        <RouterLink to="/" >专题</RouterLink>
      </div>
    </div>
  </div>
</template>

<script>
// import {ref,onMounted} from 'vue'
import { useWindowScroll } from '@vueuse/core'
import HeaderNav from './headerNav.vue'
export default {
  name: 'AppHeaderSticky',
  components: { HeaderNav },
  setup(){
    // 使用组件
    const { y } = useWindowScroll()
    return { y }
    // 传统的
    // const y = ref(0)
    // onMounted(()=>{
    //     window.onscroll=()=>{
    //         const scrollTop = document.documentElement.scrollTop
    //         y.value = scrollTop
    //     }
    // })
    // return {y}

  }
}
</script>

<style scoped lang='less'>
.app-header-sticky {
  width: 100%;
  height: 80px;
  position: fixed;
  left: 0;

  top: 0;
  z-index: 999;
  background-color: #fff;
  border-bottom: 1px solid #e4e4e4;
//   负数向上移动
  transform: translateY(-100%);
  opacity: 0;
  &.show{
    transition: all 0.3s linear;//所有的CSS属性变化在0.3秒内按线性方式完成过渡。
    transform: none;
    opacity: 1;
  }
  .container {
    display: flex;
    align-items: center;
  }
  .logo {
    width: 200px;
    height: 80px;
    background: url(../assets/images/logo.png) no-repeat  right 2px;
    background-size: 160px auto;
  }
  .right {
    width: 220px;
    display: flex;
    text-align: center;
    padding-left: 40px;
    border-left: 2px solid @xtxColor;
    a {
      width: 38px;
      margin-right: 40px;
      font-size: 16px;
      line-height: 1;
      &:hover {
        color: @xtxColor;
      }
    }
  }
}
</style>
